
package JET.Frames.recorderframe;

import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;

/**
 *
 * @author 057Ry
 */
public class RecordChartPanelMoueWheelListener implements MouseWheelListener
{
    RecorderChartPanel rcp;

    public RecordChartPanelMoueWheelListener(RecorderChartPanel rcp)
    {
        this.rcp = rcp;
    }


    public void mouseWheelMoved(MouseWheelEvent e) {
        double ogx = rcp.scrToGraphX(e.getX());     //old graphic x
        double ogy = rcp.scrToGraphY(e.getY());     //old graphic y
        //System.out.println("ogx: "+ogx+" ogy: "+ogy);

        int steps = e.getWheelRotation();
        double nScaleX=1.;
        double nScaleY=1.;

        if (steps<0) {
            nScaleX = rcp.scaleX*1.2;
            nScaleY = rcp.scaleY*1.2;
        }
        else if (steps>0) {
            nScaleX = rcp.scaleX/1.2;
            nScaleY = rcp.scaleY/1.2;
        }
        
        if (nScaleX<=0) nScaleX = 0.01;
        else if (nScaleX>=1000000) nScaleX=1000000.;
        if (nScaleY<=0) nScaleY = 0.01;
        else if (nScaleY>=1000000) nScaleY=1000000.;

        rcp.setScaleX(nScaleX);
        rcp.setScaleY(nScaleY);

        double ngx = rcp.scrToGraphX(e.getX());     //new graphic x
        double ngy = rcp.scrToGraphY(e.getY());     //new graphic y
        //System.out.println("ngx: "+ngx+" ngy: "+ngy);

        double gdx = ngx-ogx;       //graphic delta x
        double gdy = ngy-ogy;       //graphic delta y
        //System.out.println("gdx: "+gdx+" gdy: "+gdy);

        double sdx = rcp.g2sX(gdx);
        double sdy = rcp.g2sY(gdy);
        //System.out.println("sdx: "+sdx+" sdy: "+sdy);

        rcp.vX += sdx;
        rcp.vY += sdy;
        rcp.updateUI();
    }

}
